package com.tmall.testgen.plugin.views.action;

import org.eclipse.jface.action.Action;

import com.tmall.testgen.client.ClientDataCenter;
import com.tmall.testgen.client.commond.SendCommondInstance;
import com.tmall.testgen.client.config.TargetProjectConfig;
import com.tmall.testgen.client.socket.SocketClient;
import com.tmall.testgen.plugin.views.GenCodeMonitorView;
import com.tmall.testgen.plugin.views.vo.TreeParent;
import com.tmall.testgen.server.socket.CommondEnum;

/**
 * 停止
 * 
 * @author star
 * 
 */
public class StopAction extends Action {
	public static final String ID = "stopAction";
	private GenCodeMonitorView listener;
	
	private TreeParent interceptRoot;
	
	public StopAction(GenCodeMonitorView listener) {
		super("停止",Action.AS_CHECK_BOX);
		setId(ID);
		setToolTipText("stop test");
		setImageDescriptor(ImageManeger.getImageDescriptor(ImageManeger.USED_STOP));
		this.listener = listener;
	}

	
	public void run() {
		if(!SocketClient.getInstance().isStart())
			return;
		
		//TODO:需要弹出确认框，确认后所有按钮灰掉
	//	MyMessageDialog.openConfirmDialog(this.get, msg);
		
		
		SendCommondInstance.getSendCommond().sendCommond(CommondEnum.Stop);
		
		interceptRoot.getParent().removeAllChildren();
		listener.getViewer().refresh();
		
		SocketClient.getInstance().closeSocket();
		//changeChecked(isChecked());
		ClientDataCenter.clear();
		TargetProjectConfig.clear();
		
		listener.beginMonitor(false);
		setChecked(false);
	}
	public void changeChecked(boolean checked){
		setEnabled(!checked);
		setChecked(checked);
		if(!checked){
			setImageDescriptor(ImageManeger.getImageDescriptor(ImageManeger.USED_STOP));
		}else{
			setImageDescriptor(ImageManeger.getImageDescriptor(ImageManeger.UN_USED_STOP));
		}
	}


	public TreeParent getInterceptRoot() {
		return interceptRoot;
	}


	public void setInterceptRoot(TreeParent interceptRoot) {
		this.interceptRoot = interceptRoot;
	}
	
	
	
}
